using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace OffsetPath
{
    public class GraphicEndClassH
    {
        public PuntoDueD a = new PuntoDueD(0.0, 0.0);
        public PuntoDueD b = new PuntoDueD(1.0, 1.0);

        private GraphicsPath MethodA(OffsetProfilo2D A_0)
        {
            GraphicsPath path = new GraphicsPath();
            if (A_0.GetListaLineaArco().Count != 0)
            {
                for (int i = 0; i < A_0.GetListaLineaArco().Count; i++)
                {
                    if (A_0.GetListaLineaArco()[i] is ForseLineaClassA)
                    {
                        PuntoDueD puntoDueD = A_0.GetListaLineaArco()[i].h();
                        PuntoDueD x2 = A_0.GetListaLineaArco()[i].i();
                        this.MethodA(puntoDueD);
                        this.MethodA(x2);
                        path.AddLine((float) puntoDueD.X, (float) puntoDueD.Y, (float) x2.X, (float) x2.Y);
                    }
                    else if (A_0.GetListaLineaArco()[i] is ForseArco2ClassQ)
                    {
                        ClassAb classAb = new ClassAb();
                        int pensoAngoloIniziale = 0;
                        int pensoAngoloFinale = 0;
                        this.EstraiProprietaDaArcoInElisse(A_0.GetListaLineaArco()[i] as ForseArco2ClassQ, classAb, ref pensoAngoloIniziale, ref pensoAngoloFinale);
                        if (pensoAngoloFinale == 0)
                        {
                            pensoAngoloFinale = 1;
                        }
                        int num4 = (int) classAb.l();
                        if (num4 == 0)
                        {
                            num4 = 1;
                        }
                        int num5 = (int) classAb.n();
                        if (num5 == 0)
                        {
                            num5 = 1;
                        }
                        path.AddArc((float) classAb.GetEndPnt().X, (float) classAb.GetStartPoint().Y, (float) num4, (float) num5, (float) pensoAngoloIniziale, (float) pensoAngoloFinale);
                    }
                }
                path.CloseFigure();
            }
            return path;
        }

        private void MethodA(PuntoDueD A_0)
        {
            A_0.X -= this.a.X;
            A_0.Y -= this.a.Y;
            A_0.X *= this.b.X;
            A_0.Y *= this.b.Y;
        }

        public void DisegnaLinea(ForseLineaClassA classA0, Graphics A_1, Pen A_2)
        {
            PuntoDueD puntoDueD = classA0.h();
            PuntoDueD x2 = classA0.i();
            this.MethodA(puntoDueD);
            this.MethodA(x2);
            try
            {
                A_1.DrawLine(A_2, (float) puntoDueD.X, (float) puntoDueD.Y, (float) x2.X, (float) x2.Y);
            }
            catch (Exception)
            {
            }
        }

        public void MethodA(ClassAb A_0, Graphics A_1, Brush A_2)
        {
            PuntoDueD puntoDueD = new PuntoDueD(A_0.GetEndPnt());
            PuntoDueD x2 = new PuntoDueD(A_0.GetStartPoint());
            this.MethodA(puntoDueD);
            this.MethodA(x2);
            float a = (float) puntoDueD.X;
            if (this.b.X < 0.0)
            {
                a = (float) x2.X;
            }
            float b = (float) x2.Y;
            if (this.b.X < 0.0)
            {
                b = (float) puntoDueD.Y;
            }
            try
            {
                A_1.FillRectangle(A_2, a, b, (float) Math.Abs((double) (puntoDueD.X - x2.X)), (float) Math.Abs((double) (puntoDueD.Y - x2.Y)));
            }
            catch (Exception)
            {
            }
        }

        public void MethodA(ClassAb A_0, Graphics A_1, Pen A_2)
        {
            PuntoDueD puntoDueD = new PuntoDueD(A_0.GetEndPnt());
            PuntoDueD x2 = new PuntoDueD(A_0.GetStartPoint());
            this.MethodA(puntoDueD);
            this.MethodA(x2);
            float a = (float) puntoDueD.X;
            if (this.b.X < 0.0)
            {
                a = (float) x2.X;
            }
            float b = (float) x2.Y;
            if (this.b.X < 0.0)
            {
                b = (float) puntoDueD.Y;
            }
            try
            {
                A_1.DrawRectangle(A_2, a, b, (float) Math.Abs((double) (puntoDueD.X - x2.X)), (float) Math.Abs((double) (puntoDueD.Y - x2.Y)));
            }
            catch (Exception)
            {
            }
        }

        public void MethodA(ClassAd A_0, Graphics A_1, Brush A_2)
        {
            GraphicsPath path = new GraphicsPath();
            PuntoDueD puntoDueD = new PuntoDueD(A_0.a);
            PuntoDueD x2 = new PuntoDueD(A_0.b);
            PuntoDueD x3 = new PuntoDueD(A_0.c);
            this.MethodA(puntoDueD);
            this.MethodA(x2);
            this.MethodA(x3);
            path.AddLine((float) puntoDueD.X, (float) puntoDueD.Y, (float) x2.X, (float) x2.Y);
            path.AddLine((float) x2.X, (float) x2.Y, (float) x3.X, (float) x3.Y);
            path.AddLine((float) x3.X, (float) x3.Y, (float) puntoDueD.X, (float) puntoDueD.Y);
            A_1.FillPath(A_2, path);
        }

        public void MethodA(ClassAd A_0, Graphics A_1, Pen A_2)
        {
            this.DisegnaLinea(new ForseLineaClassA(A_0.a, A_0.b), A_1, A_2);
            this.DisegnaLinea(new ForseLineaClassA(A_0.b, A_0.c), A_1, A_2);
            this.DisegnaLinea(new ForseLineaClassA(A_0.c, A_0.a), A_1, A_2);
        }

        public void MethodA(PolygonalShape A_0, Graphics A_1, Brush A_2)
        {
            if (A_0.GetExternPolygon().GetListaLineaArco().Count != 0)
            {
                GraphicsPath path = this.MethodA(A_0.GetExternPolygon());
                for (int i = 0; i < A_0.holesCount(); i++)
                {
                    if (A_0.GetHolesProfileAt(i).GetListaLineaArco().Count > 2)
                    {
                        path.AddPath(this.MethodA(A_0.GetHolesProfileAt(i)), false);
                    }
                }
                path.FillMode = FillMode.Alternate;
                try
                {
                    A_1.FillPath(A_2, path);
                }
                catch (Exception)
                {
                }
            }
        }

        //public void DisegnaPolygonoAncheConIsole(PolygonalShape A_0, Graphics A_1, Pen A_2)
        //{
        //    /*
        //     * Devo studiare  archi , quindi qui creo profilo e lo stampo..
        //     */

        //    var line = new ForseLineaClassA(0, 0, 50, 0);
        //    var line1 = new ForseLineaClassA(50, 0, 50, 50);
        //    var line2 = new ForseLineaClassA(50, 50, 0, 50);
        //    var line3 = new ForseLineaClassA(0, 50, 0, 0);
        //    /* ok pini. pfin raggio centro se uno o l'altro . vedere se si definisce il centro.., counterclokwise..*/ 
        //    var arc = new ForseArco2ClassQ(new PuntoDueD(0, 50), new PuntoDueD(0, 0), 50, true, false);


        //    var elements = new List<ClasseBaseLineaArcoClassAf>();

        //    elements.Add(line);
        //    elements.Add(line1);
        //    elements.Add(line2);
        //    elements.Add(arc);

        //    var profile = new OffsetProfilo2D();

        //    var co = new ClassO_List_LineArco();

        //    co.AggiungiElementiLineaArco(elements);

        //    profile.MethodB(co);

        //    this.DisegnaProfilo(profile, A_1, A_2);

        //    //this.DisegnaProfilo(A_0.GetExternPolygon(), A_1, A_2);
        //    //for (int i = 0; i < A_0.holesCount(); i++)
        //    //{
        //    //    this.DisegnaProfilo(A_0.GetHolesProfileAt(i), A_1, A_2);
        //    //}
        //}

         /// <summary>
         /// Metodo Ok
         /// </summary>
         /// <param name="A_0"></param>
         /// <param name="A_1"></param>
         /// <param name="A_2"></param>
        public void DisegnaPolygonoAncheConIsole(PolygonalShape A_0, Graphics A_1, Pen A_2)
        {
            this.DisegnaProfilo(A_0.GetExternPolygon(), A_1, A_2);
            for (int i = 0; i < A_0.holesCount(); i++)
            {
                this.DisegnaProfilo(A_0.GetHolesProfileAt(i), A_1, A_2);
            }
        }

        public void MethodA(ClassAn A_0, Graphics A_1, Brush A_2)
        {
            ClassAb classAb = new ClassAb();
            int pensoAngoloIniziale = 0;
            int pensoAngoloFinale = 0;
            this.EstraiProprietaDaArcoInElisse(A_0.j(), classAb, ref pensoAngoloIniziale, ref pensoAngoloFinale);
            if (pensoAngoloFinale == 0)
            {
                pensoAngoloFinale = 1;
            }
            int num3 = (int) classAb.l();
            if (num3 == 0)
            {
                num3 = 1;
            }
            int num4 = (int) classAb.n();
            if (num4 == 0)
            {
                num4 = 1;
            }
            GraphicsPath path = new GraphicsPath();
            path.AddArc((float) classAb.GetEndPnt().X, (float) classAb.GetStartPoint().Y, (float) num3, (float) num4, (float) pensoAngoloIniziale, (float) pensoAngoloFinale);
            PuntoDueD puntoDueD = A_0.j().GetLinea().h();
            PuntoDueD x2 = A_0.j().GetLinea().i();
            this.MethodA(puntoDueD);
            this.MethodA(x2);
            path.AddLine((float) x2.X, (float) x2.Y, (float) puntoDueD.X, (float) puntoDueD.Y);
            A_1.FillPath(A_2, path);
        }

        /// <summary>
        ///  Mai usato
        /// </summary>
        /// <param name="A_0"></param>
        /// <param name="A_1"></param>
        /// <param name="A_2"></param>
        public void MethodA(ClassAn A_0, Graphics A_1, Pen A_2)
        {
            this.DisegnaArco(A_0.j(), A_1, A_2);
            this.DisegnaLinea(A_0.j().GetLinea(), A_1, A_2);
        }

        public void MethodA(ClassG A_0, Graphics A_1, Brush A_2)
        {
            ClassAb classAb = new ClassAb();
            A_0.f(classAb);
            this.MethodA(classAb.GetStartPoint());
            this.MethodA(classAb.GetEndPnt());
            try
            {
                A_1.FillEllipse(A_2, (float) classAb.GetEndPnt().X, (float) classAb.GetStartPoint().Y, (float) classAb.l(), (float) classAb.n());
            }
            catch (Exception)
            {
            }
        }

        public void MethodA(ClassG A_0, Graphics A_1, Pen A_2)
        {
            ClassAb classAb = new ClassAb();
            A_0.f(classAb);
            this.MethodA(classAb.GetStartPoint());
            this.MethodA(classAb.GetEndPnt());
            A_1.DrawEllipse(A_2, (float) classAb.GetEndPnt().X, (float) classAb.GetStartPoint().Y, (float) classAb.l(), (float) classAb.n());
        }

        public void DisegnaArco(ForseArco2ClassQ arco, Graphics GraphicsA_1, Pen penA_2)
        {
            ClassAb classAb = new ClassAb();
            int pensoAngoloIniziale = 0;
            int ampiezzaAngolo = 0;
            this.EstraiProprietaDaArcoInElisse(arco, classAb, ref pensoAngoloIniziale, ref ampiezzaAngolo);
            if (ampiezzaAngolo == 0)
            {
                ampiezzaAngolo = 1;
            }
            int num3 = (int) classAb.l();
            if (num3 == 0)
            {
                num3 = 1;
            }
            int num4 = (int) classAb.n();
            if (num4 == 0)
            {
                num4 = 1;
            }
            try
            {
                GraphicsA_1.DrawArc(penA_2, (float) classAb.GetEndPnt().X, (float) classAb.GetStartPoint().Y, (float) num3, (float) num4, (float) pensoAngoloIniziale, (float) ampiezzaAngolo);
            }
            catch (Exception)
            {
            }
        }

        public void MethodA(OffsetProfilo2D A_0, Graphics A_1, Brush A_2)
        {
            GraphicsPath path = this.MethodA(A_0);
            try
            {
                A_1.FillPath(A_2, path);
            }
            catch (Exception)
            {
            }
        }

        public void DisegnaProfilo(OffsetProfilo2D A_0, Graphics A_1, Pen A_2)
        {
            for (int i = 0; i < A_0.GetListaLineaArco().Count; i++)
            {
                if (A_0.GetListaLineaArco()[i] is ForseLineaClassA)
                {
                    this.DisegnaLinea(A_0.GetListaLineaArco()[i] as ForseLineaClassA, A_1, A_2);
                }
                else if (A_0.GetListaLineaArco()[i] is ForseArco2ClassQ)
                {
                    this.DisegnaArco(A_0.GetListaLineaArco()[i] as ForseArco2ClassQ, A_1, A_2);
                }
            }
        }

        private void EstraiProprietaDaArcoInElisse(ForseArco2ClassQ A_0, ClassAb A_1, ref int pensoAngoloIniziale, ref int pensoAngoloFinale)
        {
            PuntoDueD puntoDueD = A_0.e();
            A_1.MethodA(puntoDueD.X - A_0.d, puntoDueD.Y + A_0.d, puntoDueD.X + A_0.d, puntoDueD.Y - A_0.d);
            this.MethodA(A_1.GetEndPnt());
            this.MethodA(A_1.GetStartPoint());
            A_1.d(A_1);
            PuntoDueD x2 = A_0.GetLinea().h();
            PuntoDueD x3 = A_0.GetLinea().i();
            this.MethodA(x2);
            this.MethodA(x3);
            ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(puntoDueD, x2);
            ClassAtPuntoIncrementale at2 = new ClassAtPuntoIncrementale(puntoDueD, x3);
            ClassAtPuntoIncrementale at3 = new ClassAtPuntoIncrementale(100.0, 0.0);
            double num = at3.d(classAt) * ClassK.toDegree;
            double num2 = 0.0;
            bool flag = (this.b.X * this.b.Y) < 0.0;
            if (A_0.b ^ flag)
            {
                num2 = classAt.d(at2) * ClassK.toDegree;
            }
            else
            {
                num2 = -classAt.c(at2) * ClassK.toDegree;
            }
            pensoAngoloIniziale = (int) num;
            pensoAngoloFinale = (int) num2;
        }
    }
}

